package com.fengye.algorithms.leecode;

import com.fengye.algorithms.leecode.common.TreeNode;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author fengye
 * @Date 2023/4/20 9:09
 **/
public class TwoSumIvInputIsABst653 {

    Set<Integer> set = new HashSet<Integer>();

    public boolean findTarget(TreeNode root, int k) {
        if (root == null) {
            return false;
        }
        if (set.contains(k - root.val)) {
            return true;
        }
        set.add(root.val);
        return findTarget(root.left, k) || findTarget(root.right, k);
    }



    public boolean findTarget1(TreeNode root, int k) {
        if(root == null) {
            return false;
        }

        if(set.contains(k - root.val)) {
            return true;
        }
        set.add(root.val);
        return findTarget1(root.left, k) || findTarget1(root.right, k);
    }
}
